import type { App } from "vue";
const getAppConfig = () => {
  return localStorage.getItem('app_config') ? JSON.parse(localStorage.getItem('app_config')!) : undefined; 
}

export default {
  install (app: App) {
    const appConfig = getAppConfig();
    if (appConfig) {
      if (appConfig.config.ability.websocket) {
        import('./socket').then(res => {
          const SocketClient = res.default;
          const socketClient = new SocketClient();
          app.config.globalProperties.$socketClient = socketClient;
        })
      };
      if (appConfig.config.ability.stomp) {
        import('./stomp').then(res => {
          const StompClient = res.default;
          const stompClient = new StompClient;
          app.config.globalProperties.$stompClient = stompClient;
        })
      }
      if (appConfig.config.ability.sse) {
        import('./sse').then(res => {
          const SSEClient = res.default;
          const sseClient = new SSEClient();
          app.config.globalProperties.$sseClient = sseClient;
        })
      }
    }
  }
}